package pers.lonestar.framework.utils;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;

import pers.lonestar.framework.utils.support.read.ExcelReaderBuilder;
import pers.lonestar.framework.utils.support.read.ExcelReaderSheetBuilder;
import pers.lonestar.framework.utils.support.utils.StringUtil;
import pers.lonestar.framework.utils.support.write.ExcelWriterBuilder;
import pers.lonestar.framework.utils.support.write.ExcelWriterSheetBuilder;

public class ExcelUtils {
    public static ExcelWriterBuilder write(File file) {
        if (file == null) {
            throw new IllegalArgumentException("Excel File must not be null");
        }
        ExcelWriterBuilder writerBuilder = new ExcelWriterBuilder();
        writerBuilder.file(file);
        return writerBuilder;
    }

    public static ExcelWriterBuilder write(String fileName) {
        if (StringUtil.isEmpty(fileName)) {
            throw new IllegalArgumentException("Excel filename must not be null or empty");
        }
        ExcelWriterBuilder writerBuilder = new ExcelWriterBuilder();
        return writerBuilder.file(new File(fileName));
    }

    public static ExcelWriterBuilder write(OutputStream outputStream) {
        if (outputStream == null) {
            throw new IllegalArgumentException("Excel OutputStream must not be null");
        }
        ExcelWriterBuilder writerBuilder = new ExcelWriterBuilder();
        writerBuilder.file(outputStream);
        return writerBuilder;
    }

    public static ExcelWriterSheetBuilder writeSheet() {
        return writeSheet(null, null);
    }

    public static ExcelWriterSheetBuilder writeSheet(String sheetName) {
        return writeSheet(null, sheetName);
    }

    public static ExcelWriterSheetBuilder writeSheet(Integer sheetIndex) {
        return writeSheet(sheetIndex, null);
    }

    public static ExcelWriterSheetBuilder writeSheet(Integer sheetIndex, String sheetName) {
        ExcelWriterSheetBuilder writerSheetBuilder = new ExcelWriterSheetBuilder();
        if (sheetIndex != null) {
            writerSheetBuilder.sheetIndex(sheetIndex);
        }
        if (sheetName != null) {
            writerSheetBuilder.sheetName(sheetName);
        }
        return writerSheetBuilder;
    }

    public static ExcelReaderBuilder read(File file) {
        if (file == null) {
            throw new IllegalArgumentException("Excel File must not be null");
        }
        ExcelReaderBuilder readerBuilder = new ExcelReaderBuilder();
        readerBuilder.file(file);
        return readerBuilder;
    }

    public static ExcelReaderBuilder read(String fileName) {
        if (StringUtil.isEmpty(fileName)) {
            throw new IllegalArgumentException("Excel filename must not be null or empty");
        }
        ExcelReaderBuilder readerBuilder = new ExcelReaderBuilder();
        readerBuilder.file(fileName);
        return readerBuilder;
    }

    public static ExcelReaderBuilder read(InputStream inputStream) {
        if (inputStream == null) {
            throw new IllegalArgumentException("Excel InputStream must not be null");
        }
        ExcelReaderBuilder readerBuilder = new ExcelReaderBuilder();
        readerBuilder.file(inputStream);
        return readerBuilder;
    }

    public static ExcelReaderSheetBuilder readSheet() {
        return readSheet(null, null);
    }

    public static ExcelReaderSheetBuilder readSheet(Integer sheetIndex) {
        return readSheet(sheetIndex, null);
    }

    public static ExcelReaderSheetBuilder readSheet(String sheetName) {
        return readSheet(null, sheetName);
    }

    public static ExcelReaderSheetBuilder readSheet(Integer sheetIndex, String sheetName) {
        ExcelReaderSheetBuilder readerSheetBuilder = new ExcelReaderSheetBuilder();
        if (sheetIndex != null) {
            readerSheetBuilder.sheetIndex(sheetIndex);
        }
        if (sheetName != null) {
            readerSheetBuilder.sheetName(sheetName);
        }
        return readerSheetBuilder;
    }

}
